package com.liying;

import java.util.HashSet;
import java.util.Set;

public class SetOperation {

	/**
	 * 求并集
	 * @param xSet
	 * @param ySet
	 * @return
	 */
	public static HashSet<String> getUnion(Set<String> xSet,
			Set<String> ySet) {
		HashSet<String> set = new HashSet<String>();
		set.addAll(xSet);
		set.addAll(ySet);
		return set;
	}
	
	/**
	 * 求交集
	 * @param xSet
	 * @param ySet
	 * @return
	 */
	public static HashSet<String> getIntersection(Set<String> xSet,
			Set<String> ySet) {
		HashSet<String> set = new HashSet<String>();
		set.addAll(xSet);
		set.retainAll(ySet);
		return set;
	}
	
	/**
	 * 求差集
	 * @param xSet
	 * @param itself
	 * @param ySet
	 * @return
	 */
	public static HashSet<String> getSubtraction(Set<String> xSet,
			String itself, Set<String> ySet) {
		HashSet<String> set = new HashSet<String>();
		set.addAll(xSet);
		set.remove(itself); // 不包含节点本身
		set.removeAll(ySet);
		return set;
	}
}
